package com.ruoyi.project.module.ordersDetail.controller;

import com.ruoyi.common.constant.ErpEnums;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.UserUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.module.ordersDetail.domain.OrdersDetail;
import com.ruoyi.project.module.ordersDetail.service.IOrdersDetailService;
import com.ruoyi.project.system.dept.service.IDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 正常订单
  * @创建人    cbx
  * @创建时间  2018/9/15 0015 上午 9:53
  * @描述
  */
@Controller
@RequestMapping("/module/normalOrder")
public class NormalOrderController extends BaseController {

    private String prefix = "module/ordersDetail";

    @Autowired
    private IOrdersDetailService ordersDetailService;
    @Autowired
    private IDeptService deptService;


    @RequiresPermissions("module:normalOrder:view")
    @GetMapping()
    public String ordersDetail(ModelMap mmap) {
        mmap.put("depList", deptService.selectDeptAll());
        return prefix + "/normalOrder";
    }


    /**
     * 查询订单详情列表
     */
    @RequiresPermissions("module:normalOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrdersDetail ordersDetail) {
        startPageChange();

        if("".equals(ordersDetail.getCompanyID())||ordersDetail.getCompanyID()==null){
            ordersDetail.setCompanyID(UserUtils.getDepId());
        }else if("100".equals(ordersDetail.getCompanyID())){
            ordersDetail.setCompanyID("");
        }

        //根据公司id查询订单
        List<OrdersDetail> list = ordersDetailService.selectNormalOrder(ordersDetail);

        List<OrdersDetail> sumCountList = ordersDetailService.selectSumCountNormalOrder(ordersDetail);
        return getDataTableAsSum(list, sumCountList);
    }






}
